import {onMounted} from 'vue';
import '//at.alicdn.com/t/c/font_4773561_1wig5mzm7kr.js';
import axios from "axios";
import {message} from "ant-design-vue";

export function useOml2d() {
    // 配置可以根据主题的实际情况进行获取，这里写一个默认的
    const oml2dOptions = {
        menus: {
            items: () => [
                {
                    id: "home",
                    icon: "icon-xingqiu",
                    title: "我的数字花园",
                    onClick: () => window.open("https://www.yuque.com/yuque-zdhij")
                }, {
                    id: 'Rest',
                    icon: 'icon-shuijue',
                    title: '休息',
                    onClick(oml2d: any): void {
                        oml2d.stageSlideOut()
                    }
                }, {
                    id: 'SwitchModel',
                    icon: 'icon-yqfqiehuan',
                    title: '切换模型',
                    onClick(oml2d: any): void {
                        oml2d.loadNextModel().then(()=>{
                            message.success('切换成功')
                        })
                    }
                }, {
                    id: 'About',
                    icon: 'icon-guanyuwomen',
                    title: '关于博主',
                    onClick: () => window.open("https://www.yuque.com/yuque-zdhij")
                }]
        },
        models: [{
            path: 'https://fengqi-bucket.oss-cn-chengdu.aliyuncs.com/Kar98k-normal/model.json',
            scale: 0.1,
            stageStyle: {
                width: 400,
                height: 400
            }
        }],
        parentElement: document.body,
        primaryColor: "#38bdf8",
        sayHello: false,
        tips: {
            style: {
                width: 230,
                height: 120,
                left: "calc(50% + 6px)",
                top: "-100px"
            },
            mobileStyle: {
                width: 180,
                height: 80,
                left: "calc(50% - 30px)",
                top: "-100px"
            },
            // welcomeTips:{
            //     message: {
            //         afternoon: '下午好',
            //     },
            // },
            idleTips: {
                interval: 900000,
                message: function() {
                    return axios.get("https://v1.hitokoto.cn?c=i").then((function(o) {
                        return o.data.hitokoto
                    })).catch((function(o) {
                        console.error(o)
                    }))
                }
            }
        }
    };
    onMounted(async () => {
        if (oml2dOptions) {
            const {loadOml2d} = await import('oh-my-live2d');
            loadOml2d(oml2dOptions);
        }
    });
}
